home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / mnp_c.zip / ASYNC.ASM next >
Assembly Source File  |  1990-05-16  |  6KB  |  315 lines

  1.     title        async.asm
  2.     page    60,132
  3. ;==============================================================================
  4. ;
  5. ;                   The Microcom MNP Library
  6. ;                    (Microsoft C Version)
  7. ;
  8. ;------------------------------------------------------------------------------
  9. ;
  10. ;        ASYNC - Async I/O interrupt handler management routines
  11. ;                (set/clear interrupt routines also here)
  12. ;
  13. ;---------------------------------------------------------------------------
  14. ;
  15. ;    Modification History:
  16. ;
  17. ;    4/1/87 - Compuserve V1.0
  18. ;
  19. ;==============================================================================
  20. ;
  21. ic_imr    equ    21h            ;i/o address of interrupt mask reg
  22.  
  23. ; Public declarations
  24.     public    _drvr_ins
  25.     public    _drvr_rem
  26.     public    _clr_int
  27.     public    _set_int
  28. ;    public    _port_add
  29.     extrn    _port_add:word
  30. ;    public    _hard_int
  31. ;    public    _chan_no
  32.     extrn    _chan_no:word
  33.  
  34. ; Externals
  35.     extrn    _ascode:near
  36.  
  37. ; Data Segment
  38. _data    segment word public 'DATA'
  39. _data    ends
  40. dgroup    group    _data
  41. _data    segment word public 'DATA'
  42.     assume    ds:dgroup
  43.  
  44. ;    public    _linestat
  45.     extrn    _linestat:byte
  46. ;    public    _iir_add
  47.     extrn    _iir_add:word
  48.     public    _async
  49.  
  50.     extrn    _baudrate:byte
  51.     
  52. _hard_int    db    0            ;hardware interrupt #
  53. ;_port_add dw    0                ;base address of sio hardware
  54. ;_chan_no dw    0                ;channel # being used
  55. ;
  56.     db    100 dup(?)
  57. stack    equ    $
  58. drvr_active    db    0
  59. ;_linestat    db    ?
  60. old_vct     dw    ?
  61.         dw    ?
  62. ;_iir_add     dw    ?
  63. ic_imr_sav    db    ?
  64. ;
  65. _data    ends
  66.  
  67. _text    segment byte public 'CODE'
  68.     assume    cs:_text,ds:dgroup
  69.  
  70.     extrn    cdsg:word
  71.  
  72.     page
  73. ;PUBLIC---------------------------------------------------------------------
  74. ;
  75. ;    _drvr_ins - install async interrupt handler and set up async card
  76. ;
  77. ;---------------------------------------------------------------------------
  78.  
  79. _drvr_ins    proc    near
  80.         
  81.     push    bp
  82.     mov    bp,sp
  83.  
  84.     push    bx
  85.     push    dx
  86.     push    es
  87.  
  88.     cmp    drvr_active,1        ;already installed ?
  89.     jne    doit                ;no, go install
  90.     jmp    done
  91.  
  92. doit:
  93.     mov    ax,_chan_no        ; get channel number
  94.     mov    _port_add,03f8h    ; assume port 1
  95.     mov    _hard_int,0ch
  96.     cmp    al,0                ; is it 1?
  97.     je    do1                ; yes-go on
  98.     mov    _port_add,02f8h    ; no-setup for port 2
  99.     dec    _hard_int
  100. do1:
  101.     in    al,ic_imr
  102.     jmp    short $+2
  103.     mov    ic_imr_sav,al
  104.     mov    al,0ffh
  105.     out    ic_imr,al
  106.  
  107.     mov    ah,35h            ;ask for current vector contents
  108.     mov    al,_hard_int        ;specify which vector
  109.     int    21h
  110.  
  111.     mov    old_vct,bx        ;save current vector values
  112.     mov    old_vct+2,es
  113.  
  114.     mov    dx,offset _async
  115.     mov    ah,25h            ;install new vector values
  116.     mov    al,_hard_int
  117.     push    ds                ;save current ds
  118.     push    cs
  119.     pop    ds                ;ds = cs
  120.     int    21h
  121.     pop    ds                ;restore ds
  122.  
  123.     mov    ax,_port_add
  124.     inc    ax
  125.     inc    ax
  126.     mov    _iir_add,ax
  127. ;
  128.     mov    drvr_active,1
  129. ;
  130. ;      initialize rs-232 driver to character format and baud rate
  131. ;
  132.     mov    al,_baudrate
  133.     mov    cl,5                ;adjust for format
  134.     shl    al,cl            ;move  into correct field
  135.     or    al,03            ;set up 8 bits, no parity, 1 stop bit
  136.     xor    ah,ah            ;rom bios control code
  137.     mov    dx,_chan_no        ;point to port number
  138.     int    14h                ;rom bios interrupt
  139. ;
  140. ;    set current modem status
  141. ;
  142.     mov    dx,_port_add
  143.     add    dx,6                ;point to modem status register
  144.     in    al,dx
  145.     jmp    $+2
  146.     nop
  147.     in    al,dx            ;do it again in case change was waiting
  148.     mov    _linestat,al
  149. ;
  150. ;    enable modem status, rcvr and xmtr interrupts
  151. ;
  152.     sub    dx,5                ;point to interrupt enable register
  153.     mov    al,00001011b
  154.     out    dx,al
  155.     jmp    $+2
  156.     nop
  157. ;
  158. ;    clear pending interrupts
  159. ;
  160.     inc    dx                   ;point to interrupt identification reg
  161.     in    al,dx               ;clear xmtr interrupt by reading iir
  162.     jmp    $+2
  163.     nop
  164.     sub    dx,2                   ;point to receive data buffer
  165.     in    al,dx               ;clear rcvr interrupt by reading rxb
  166.     jmp    $+2
  167.     nop
  168. ;
  169. ;    setup dtr, rts & interrupt hardware enable
  170. ;
  171.     add    dx,4                   ;point to modem control register
  172.     mov    al,00001011b           ;enable dtr, rts and interrupt (out 2)
  173.     out    dx,al
  174.     jmp    $+2
  175.     nop
  176. ;
  177. ;      enable interrupt in controller.
  178. ;      if the port address is 2f8, use interrupt 3; otherwise use int 4.
  179. ;
  180.         mov    al,ic_imr_sav
  181.         mov    ah,0ffh - 00010000b    ;assume int 4
  182.         cmp    _port_add,02f8h        ;com2?
  183.         jne    port1            ;no-go on
  184.         mov    ah,0ffh - 00001000b    ;switch to int 3
  185. port1:        
  186.         and    al,ah            ;enable irq
  187.         out    ic_imr,al
  188.         jmp    $+2
  189.         nop
  190. ;
  191. done:
  192.         pop    es
  193.         pop    dx
  194.         pop    bx
  195.         pop    bp
  196.         ret
  197. ;
  198. _drvr_ins    endp
  199.         page
  200. ;PUBLIC---------------------------------------------------------------------
  201. ;
  202. ;    _drvr_rem - remove async interrupt handler
  203. ;
  204. ;--------------------------------------------------------------------------
  205.  
  206. _drvr_rem    proc    near
  207.         push    bp
  208.         mov    bp,sp
  209. ;
  210.         push    dx
  211. ;
  212.         cmp    drvr_active,1
  213.         jne    rdone
  214. ;
  215. ;    reinstall system interrupt handler
  216. ;
  217.         push    ds            ;save current ds
  218.         mov    ah,25h
  219.         mov    al,_hard_int
  220.         mov    dx,old_vct
  221.         mov    ds,old_vct+2
  222.         int    21h
  223.         pop    ds            ;restore ds
  224. ;
  225.         mov    drvr_active,0
  226. rdone:
  227.         pop    dx
  228.         pop    bp
  229.         ret
  230. ;
  231. _drvr_rem    endp
  232.  
  233.         page
  234. ;LOCAL----------------------------------------------------------------------
  235. ;
  236. ;    _async - async interrupt handler
  237. ;
  238. ;---------------------------------------------------------------------------
  239.  
  240. _async    proc    far
  241.     
  242.         push    bp
  243.         push    ax
  244.         push    bx
  245.         push    cx
  246.         push    dx
  247.         push    si
  248.         push    di
  249.         push    ds
  250.         push    es
  251. ;
  252.         mov    di,ss
  253.         mov    si,sp
  254. ;
  255.         mov    ax,cs:cdsg
  256.         mov    ss,ax
  257.         mov    es,ax
  258.         mov    ds,ax
  259. ;
  260.         mov    ax,offset dgroup:stack
  261.         mov    sp,ax
  262.         mov    bp,ax
  263. ;
  264.         push    di
  265.         push    si
  266. ;
  267.         cld
  268. ;
  269.         call    _ascode
  270. ;
  271.         pop    si
  272.         pop    di
  273.         mov    ss,di
  274.         mov    sp,si
  275. ;
  276.         pop    es
  277.         pop    ds
  278.         pop    di
  279.         pop    si
  280.         pop    dx
  281.         pop    cx
  282.         pop    bx
  283.         pop    ax
  284.         pop    bp
  285.         sti
  286.         iret
  287. ;
  288. _async        endp
  289.         page
  290. ;PUBLIC---------------------------------------------------------------------
  291. ;
  292. ;    _clr_int - do a cli from C
  293. ;
  294. ;---------------------------------------------------------------------------
  295.  
  296. _clr_int     proc    near
  297.         cli
  298.         ret
  299. _clr_int     endp
  300.  
  301. ;PUBLIC---------------------------------------------------------------------
  302. ;
  303. ;    _set_int - do an sti from C
  304. ;
  305. ;---------------------------------------------------------------------------
  306.  
  307. _set_int     proc    near
  308.         sti
  309.         ret
  310. _set_int     endp
  311.  
  312. _text ends
  313.  
  314.     end
  315.